import pymysql   #首先必须装这两个包
from configparser import ConfigParser

cf=ConfigParser.ConfigParser()
cf.read("conf.ini")
DATABASE=cf.get("app_info","DATABASE")
USER=cf.get("app_info","USER")
PASSWORD=cf.get("app_info","PASSWORD")
HOST=cf.get("app_info","HOST")
PORT=cf.get("app_info","PORT")
def mysql(sql):
    try:
        conn=pymysql.connect(host=HOST,user=USER,passwd=PASSWORD,db=DATABASE,port=PORT)
        cur = conn.cursor()
        cur.execute(sql)
        rows = cur.fetchall()
        conn.commit()  #这个对于增删改是必须的，否则事务没提交执行不成功
        cur.close()
        conn.close()
        return rows
    except pymysql.Error as e:
        print ("Mysql Error %d: %s" % (e.args[0], e.args[1]))


